<!--
 * @Descripttion: 
 * @version: 
 * @Author: mmzhang
 * @Date: 2021-07-21 10:45:02
 * @LastEditTime: 2022-12-09 09:56:33
-->
<template>
  <div class="appeal-list">
    <div class="header">
      <p>当前处于：<span class="current-menu">0分申诉</span><span @click="backIntegral"
          class="back-btn" v-if="origin!='process'">{{origin=='work'?'返回人员积分列表':'返回案场积分表'}}</span>
      </p>
    </div>
    <dt-search ref="search" :labelWidth="100" :xlBtn="6">
      <Button type="primary" @click="exportFun" v-if="origin!='work' || unlocking('0304020200')">导出</Button>
    </dt-search>
    <div>
      <Tabs type="card" v-model="showTab" :animated="false" @on-click="onChangeTab">
        <TabPane label="待审核" name="1"></TabPane>
        <TabPane label="已通过" name="3"></TabPane>
        <TabPane label="已驳回" name="4"></TabPane>
      </Tabs>
      <dt-grid ref="table" :page="page" :onFetch='onFetch' />
    </div>
  </div>
</template>
<script>
  import appealColumn from './appealColumn'
  import integralMgr from '@/biz/buildingHome/integral'
  import searchOpt from './search'
  import dt from '@dt/dt'
  let filter = null
  export default {
    props:['origin'],
    data() {
      return {
        showTab: '1',
        page: {
          rows: 50,
          current: 1
        },
        searchInfo: {
          officeIds: [],
          buildingName: '',
          roleIds: []
        },
        filterParams: {}
      }
    },
    components: {},
    created() {},
    beforeRouteEnter(to, from, next) {
      if (from.name != 'appealDetail') {
        filter = null
        dt.memory.remove('appeal_params')
      }
      next()
    },
    mounted() {
      let _this = this
      let retainParams = dt.memory.get('appeal_params')
      this.$refs.table.init(this, new appealColumn(this))
      this.$refs.search.init(this.$refs.table, new searchOpt(this).options(), this
        .searchInfo)

      this.$nextTick(function() {
        if (retainParams) {
          Object.keys(this.searchInfo).map(function(key) {
            retainParams[key] && (_this.searchInfo[key] = retainParams[key]) //比较key
          })
          _this.showTab = retainParams.showTab ? retainParams.showTab : '1'
          retainParams.rows && (this.page.rows = retainParams.rows)
          retainParams.page && (this.page.current = retainParams.page)
        }
        filter && _this.$refs.table.throwFilter().import(filter)
      })
    },
    methods: {
      backIntegral() {
        if(this.origin != 'process'){
          dt.memory.remove('appeal_params')
          this.$emit('onChange', true)
        }
      },
      exportFun() {
        let params = {
          ...this.filterParams,
        }
        integralMgr
          .zeroListExport(params)
          .then((res) => {})
          .catch((err) => {})
      },
      onFetch(data) {
        let params = {
          ...data,
          state: this.showTab
        }
        this.filterParams = {
          ...params
        }
        return integralMgr
          .getZeroList(params)
          .then((res) => {
            return {
              total: res.total,
              list: res.records
            }
          })
          .catch((err) => {})
      },
      // 切换tab
      onChangeTab() {
        filter = null
        // this.$refs.table.throwFilter().clear()
        // this.searchInfo = {
        //   officeIds: [],
        //   buildingName: '',
        //   roleIds: []
        // }
        this.$refs.table.clearFilter()
        this.$refs.search.reset()
        this.$refs.table.init(this, new appealColumn(this))
        // this.$refs.search.init(this.$refs.table, new searchOpt(this).options(), this
        //   .searchInfo)
        // this.$refs.table.fetch()
      },
      // 保留列表查询参数
      retainParamsFun() {
        let params = Object.assign({ showTab: this.showTab }, { showIntegral: false }, this
          .filterParams)
        dt.memory.set('appeal_params', params)
        filter = this.$refs.table.throwFilter().export()
      },
      //  审核 查看 到详情
      linkDetailFun(row) {
        this.retainParamsFun()
        this.$router.push({
          name: this.origin =='work'?'appealDetailWork':'appealDetail',
          query: {
            businessId: row.businessId, // 0分申诉id
            auditId: row.auditId
          },
        })
      },
      // 搜索
      searchFun() {
        this.$refs.table.fetch(true)
      }
    },
  }
</script>
<style lang="scss" scoped>
  .appeal-list {
    padding: 20px;

    .header {
      color: #333;
      margin-bottom: 20px;

      .current-menu {
        font-size: 20px;
        font-weight: bold;
      }

      .back-btn {
        padding: 8px 10px;
        margin-left: 15px;
        border: 1px solid #2d8cf0;
        color: #2d8cf0;
        cursor: pointer;
        border-radius: 5px;
      }
    }

  }
</style>